package com.singzi.leetcode.jianzhiOffer;

public class T0020 {
    public static void main(String[] args) {
        Solution0020 solution0020 = new Solution0020();
        System.out.println(solution0020.isNumber(" 5e5"));
    }
}
class Solution0020 {
    public boolean isNumber(String s) {

        boolean haSpace = false, hasTwoSpace = false, hasNumber = false,hasE = false;
        for(int i = 0;i < s.length();i++){
            char temp = s.charAt(i);
            if((temp <'0' || temp >'9') && temp != '.'&& temp != '+'&& temp != '-'&& temp != 'e'&& temp != 'E') return false;
            else if(s.charAt(i) != ' ' && hasTwoSpace) return false;
            else if(s.charAt(i) >='0' && s.charAt(i) <='9' || s.charAt(i) == '.'){
                hasNumber = true;
            }
            else if((temp =='e' || temp == 'E') && !hasNumber) return false;
            else if(temp =='e' || temp == 'E') {
                hasE = true;
                hasNumber = false;
            }
            else if(temp == '-' || temp == '+' && !hasE && hasNumber) return false;
            else if (hasNumber && s.charAt(i) ==' ' ) hasTwoSpace = true;
        }
        return true;

    }
}